package cn.zswltech.gruul.web.api.controller;

import cn.zswltech.gruul.api.ResourceApi;
import cn.zswltech.gruul.biz.service.ResourceService;
import cn.zswltech.gruul.common.dto.ResourceViewREQ;
import cn.zswltech.gruul.common.dto.ResourceViewRSP;
import cn.zswltech.gruul.common.exception.BaseException;
import cn.zswltech.gruul.common.exception.ResouceErrorEnum;
import cn.zswltech.gruul.common.result.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Jim
 * @version 1.0.0
 * @descripition:
 * @date 2024/3/21 15:35
 */
@RestController
@Slf4j
public class ResourceController implements ResourceApi {

    @Autowired
    private ResourceService resourceService;

    @Override
    public void packageResource() {

    }

    /**
     * 应用资源
     * @return
     */
    @PostMapping("/system/resouce")
    @Override
    public Response<ResourceViewRSP> systemResource(ResourceViewREQ req) {
        ResourceViewRSP rsp = null;
        try {
            rsp = resourceService.systemResource(req);
        } catch (BaseException e) {
            log.error(e.getErrMsg(), e);
            return Response.error(e);
        }catch (Exception e){
            log.error(ResouceErrorEnum.VIEW_SYSTEM_RESOURCE_ERROR.getErrMsg(), e);
            return Response.error(ResouceErrorEnum.VIEW_SYSTEM_RESOURCE_ERROR);
        }
        return Response.success(rsp);
    }
}
